/// @tags:
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

namespace BlueQuantum {

typedef map<int, int> mmap;

int const M = 15, N = 5e4 + 5, mod = 1e9 + 7;

int n, m;
char s[N];
int a[N][M];
mmap mp, ans;

mmap solve(char *const s) {
  mmap res, stmp, tmp;
  for (int i = 1;;) {
    if (s[i] == ')' || s[i] == '\000') {
      res[0] = i + 3;
      return res;
    }
    if (s[i + 1] == '(') {
      stmp = solve(s + i + 2);
      i += stmp[0];
    } else {
      i += 2;
    }
    if (s[i] == '>') {
      tmp = res;
      for (mmap::iterator it = stmp.begin(); it != stmp.end(); ++it) {
        mmap::iterator big = res.lower_bound(it->first);
        for (; big != res.end(); ++big) big->second *= it->second;
        if (res.begin()->first < it->first) {
          mmap::iterator sml = --res.lower_bound(it->first);
          int sum = 0;
          for (mmap::iterator iter = res.begin(); iter != sml; ++iter) {
            sum += iter->second;
            if (sum >= mod) sum -= mod;
          }
        }
      }
    } else if (s[i] == '<') {
      for (mmap::iterator it = stmp.begin(); it != stmp.end(); ++it) {}
    } else {
    }
  }
  return res;
}

inline int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    for (int j = 1; j <= n; ++j) cin >> a[j][i];
  }
  cin >> s;
  ans = solve(s);
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("expr.in", "r", stdin);
  freopen("expr.out", "w", stdout);
#endif
#endif

  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
